<?php
/**
 * P�gina principal do sistema, cont�m todos os menus da aplica��o.
*/
if( !function_exists('__autoload') )
{
    function __autoload($class_name) {
    require_once $class_name . '.php';
    }
}

SAEO::ValidarAcesso( array() );

function TirarFormatacaoProcesso($numProcesso){
	return str_replace(array(".", "/", "-"), "", $numProcesso);
}

function montaMascara($msg="", $mask="") {
        $cMask = $mask;
        $cMsg = $msg;
        //refaz máscara
        for($i=0;$i<=strlen($cMask)-1;$i++)
            if(strlen($cMsg)-1 >= $i) //verifica se existe tantos caracteres

                if($cMask[$i] != "#" && $cMsg[$i] != $cMask[$i]) {
//Verifica se o caracter da máscara é especial, se for verifica se é igual

                    $nMsg = ""; //Cria nova mensagem
                    for($b=0;$b<=strlen($cMsg)-1;$b++) //refaz mensagem
                        if($b==$i) $nMsg = $nMsg.$cMask[$i].$cMsg[$b]; //Se


                        else $nMsg = $nMsg.$cMsg[$b];
                    $cMsg = $nMsg;
                }

        return $nMsg;
    } 

?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SAEO - Sistema de Acompanhamento de Execu&ccedil;&atilde;o Or&ccedil;ament&aacute;ria - IFAL</title>
<link rel='stylesheet' href='templates/estilos.css'>
</head>
<body class='body'>
	<table width='779' border='0' cellspacing='0' cellpadding='0' align='center'>
		<tr>
    		<td height='30'><?php include 'Topo.php'; ?></td>
  		</tr>
  		<tr>
                <td><div class='titulosTabelas' style='width:779; height:20; background:url(templates/tabela.jpg)'>LISTA DE RESERVAS</div></td>
        </tr>
  		<tr>
    		<td bgcolor='#FFFFFF'>
    			<div style='margin-top: 100px; margin-bottom: 100px;'>
                                        
					<table id='dadosFornecedor' style="width: 650" border='0' cellpadding='0' align='center' bgcolor='#FFFFFF' class='detalhamento'>
						<thead class='detalhamento'>
						<tr>
							<th style="width: 40px;">Código</th>
                                                        <th style="width: 40px;">Ptres</th>
							<th style="width: 100px;">Processo</th>
							<th style="width: 400px;">Despesa</th>
							<?php
								
								if(strcmp($_GET['operacao'], "consultar") == 0){ 
							
									echo "<th>Visualizar</th>";
							
								}else if(strcmp($_GET['operacao'], "alterar") == 0){	 
							
									echo "<th>Editar</th>";
							
								}else if(strcmp($_GET['operacao'], "remover") == 0){
							
									echo "<th>Remover</th>";
								} 
							?>
						</tr>
						</thead>
						<tbody class='detalhamento' id='corpoPrograma'>
						<?php 
							$processo = TirarFormatacaoProcesso($_GET['processo']);
							$reservaDao = new Reserva();
							if(isset($_GET['processo'])){
								$reservas = $reservaDao->CarregarReservasPorProcesso($processo);
							}else if(isset($_GET['setorId'])){
								$reservas = $reservaDao->CarregarReservasPorSetor($_GET['setorId']);
							}else if(isset($_GET['campiId'])){
								$reservas = $reservaDao->CarregarReservasPorCampus($_GET['campiId']);
							}else if(isset($_GET['periodoInicio']) && isset($_GET['periodoFim'])){
								$reservas = $reservaDao->CarregarReservasPorCampus($_GET['periodoInicio']);
							}else if(isset($_GET['acaoId'])){
								$reservas = $reservaDao->CarregarReservasPorAcao($_GET['acaoId']);
							}	
							if(!$reservas){
						?>
							<tr>
								<td colspan="6" class="textoCentral">Nenhuma Reserva encontrada</td>
							</tr>
						<?php 
							}
							foreach ($reservas as $reserva){
						?>
							<tr>
								<td align="center" style='width: 100px;'><?php echo $reserva->id; ?></td>
                                                                <td align="center" style='width: 60px;'><?php echo $reserva->rateio->fonte->programa->codResumido; ?></td>
								<td><?php echo montaMascara($reserva->processo,"#####.######/####-##"); ?></td>
								<td><?php echo $reserva->despesa; ?></td>
								<td align="center" style='width: 100px;'>
								<?php
								
									if(strcmp($_GET['operacao'], "consultar") == 0){ 
							
								?>
									<a title="visualizar reserva" href="ConsultarReserva.php?idReserva=<?php echo $reserva->id; ?>">
										<img style="border: 0; margin-right: 10px;" src="templates/icon_visualizar.png" />
									</a>
								<?php 
							
									}else if(strcmp($_GET['operacao'], "alterar") == 0){	 
							
								?>
									<a title="alterar reserva" href="AlterarReserva.php?idReserva=<?php echo $reserva->id; ?>">
										<img style="border: 0; margin-right: 10px;" src="templates/edit-icon.png" />
									</a>
								<?php	
							
									}else if(strcmp($_GET['operacao'], "remover") == 0){
							
								?>
									<a title="remover reserva" href="RemoverReserva.php?idReserva=<?php echo $reserva->id; ?>">
										<img style="border: 0; margin-right: 10px;" src="templates/b_drop.png" />
									</a>
								<?php
									
									} 
								?>
									
									
								</td>
							</tr>
						<?php 
							}
						?>
                        </tbody>
						
					</table>
			
				</div>
			</td>
  		</tr>
		<tfoot>
        	<tr><?php include 'rodapeCreditos.php'; ?></tr>
        </tfoot>
	</table>
</body>
</html>